package cn.wolfcode.wolf2w.business.service.impl;


import cn.wolfcode.wolf2w.business.service.ISmsService;
import cn.wolfcode.wolf2w.business.util.SmsUtil;
import cn.wolfcode.wolf2w.common.redis.service.RedisService;
import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class SmsServiceImpl implements ISmsService {

    @Autowired
    private RedisService redisService;

    @Override
    public void sendVerifyCode(String phone) {
//        String substring = UUID.randomUUID().toString().replace("-", "").substring(6);

     Integer code = new Random().nextInt(9000)+ 1000;
        SmsUtil.sendMessage(phone,code.toString());
        //TODO存储验证码

        String key = RedisKeys.VERIFY_CODE.join(phone);

        redisService.setCacheObject(key,code.toString(),RedisKeys.VERIFY_CODE.getTime(), TimeUnit.SECONDS);


        System.err.println("验证码: " + code);

    }
}
